//index.js
//获取应用实例
const app = getApp()
var intt;
Page({
  data: {
    correct: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
    emptyPoint: [510, 510],
    points: [],
    canclick: false,
    correctPosition: [],
    steps: 0,
    currentState: "开始",
    currentTap: 'startGame',
    hour: 0,
    minute: 0,
    second: 0,
    millisecond: 0,
    int: '00:00:00',
    defaultAn: {
      duration: 1000,
      timingFunction: "ease",
    },
    audioAction: {  //自动播放暂停  play（自动播放）  pause（暂停） 
      method: 'pause'
    },
    motaiHidden: true,
    indicatorDots: false,
    autoplay: true,
    interval: 6000,
    duration: 1000,
    circular: true,
    light: "",
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    titles: [
      "最强大脑，等你来战",
      "可能我不是第一，但是解决你还是没问题的",
      "最强大脑，等你来战",
      "最强大脑，等你来战",
      "最强大脑，等你来战",
    ],

    all0:{num:1},
    all1: { num: 2 },
    all2: { num: 3 },
    all3: { num: 4 },
    all4: { num: 5 },
    all5: { num: 6 },
    all6: { num: 7 },
    all7: { num: 8 },
    all8: { num: 9 },
    all9: { num: 10 },
    all10: { num: 11 },
    all11: { num: 12 },
    all12: { num: 13 },
    all12: { num: 14 },
    all14: { num: 15 },
  },
  //页面加载的时候自动播放音乐
  onReady: function (e) {
    var that = this;
    this.audioCtx = wx.createAudioContext('myAudio');
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          imageUrl: app.globalData.imageUrl
        })
      }
    })
  },

  onLoad: function () {
    var that = this;
    getCorrectPosition(that);
    /* getNums(that);
     getAllPoints(that);*/
    that.reset();
  },
  onShow: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        })
      }
    })
    getCode(this);
    getBannder(this)
  },
  toAd:function(e){
    wx.navigateToMiniProgram({
      appId: ''+e.target.id,
      success: function (e) {
      //  console.log(e)
      },
      fail: function (e) {
      //  console.log(e)
      }
    })
  },
  rank: function () {
    wx.navigateTo({
      url: '../../pages/rank/rank',
   
    })
  },

  onShareAppMessage: function () {
    var that=this;
    var _num = Math.floor(Math.random() * that.data.titles.length);
    var _title = that.data.titles[_num];
    return {
      title: '' + _title,
      path: '/pages/index/index?id=' + wx.getStorageSync("userid"),
    }
  },
  movee:function(){
    this.setData({
      both14: "left:510rpx;transform left 1.6s"
    })
  },
  move: function (e) {
    let that = this;
    if (that.data.isReset) {

      this.startGame();
    }
    if (!this.data.canclick) {
      return;
    }
    that.setData({
      light: "light"
    })
    let _x = e.target.dataset.x;
    let _y = e.target.dataset.y;
    let _id = e.target.id;
    let emptyPoint = this.data.emptyPoint;
    let temp = this.data.emptyPoint;
    let tempPotins = [];
    let tempComparePotins = this.data.correctPosition;
    if ((Math.abs(_x - emptyPoint[0]) == 170 && _y == emptyPoint[1]) || (Math.abs(_y - emptyPoint[1]) == 170 && _x == emptyPoint[0])) {
      this.data.emptyPoint = [_x, _y];
      this.data.points[_id].x = temp[0];
      this.data.points[_id].y = temp[1];
      if (_id == 0) {
        this.data.all0.x = temp[0]
        this.data.all0.y = temp[1]
        that.setData({
          all0: this.data.all0,
          both0: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;transition all 1.6s"
        })
      } else if (_id == 1) {
        this.data.all1.x = temp[0]
        this.data.all1.y = temp[1]
        that.setData({
          all1: this.data.all1,
          both1: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;transition all 1.6s"
        })
      } else if (_id == 2) {
        this.data.all2.x = temp[0]
        this.data.all2.y = temp[1]
        that.setData({
          all2: this.data.all2,
          both2: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 3) {
        this.data.all3.x = temp[0]
        this.data.all3.y = temp[1]
        that.setData({
          all3: this.data.all3,
          both3: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 4) {
        this.data.all4.x = temp[0]
        this.data.all4.y = temp[1]
        that.setData({
          all4: this.data.all4,
          both4: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 5) {
        this.data.all5.x = temp[0]
        this.data.all5.y = temp[1]
        that.setData({
          all5: this.data.all5,
          both5: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 6) {
        this.data.all6.x = temp[0]
        this.data.all6.y = temp[1]
        that.setData({
          all6: this.data.all6,
          both6: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 7) {
        this.data.all7.x = temp[0]
        this.data.all7.y = temp[1]
        that.setData({
          all7: this.data.all7,
          both7: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 8) {
        this.data.all8.x = temp[0]
        this.data.all8.y = temp[1]
        that.setData({
          all8: this.data.all8,
          both8: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 9) {
        this.data.all9.x = temp[0]
        this.data.all9.y = temp[1]
        that.setData({
          all9: this.data.all9,
          both9: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 10) {
        this.data.all10.x = temp[0]
        this.data.all10.y = temp[1]
        that.setData({
          all10: this.data.all10,
          both10: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 11) {
        this.data.all11.x = temp[0]
        this.data.all11.y = temp[1]
        that.setData({
          all11: this.data.all11,
          both11: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 12) {
        this.data.all12.x = temp[0]
        this.data.all12.y = temp[1]
        that.setData({
          all12: this.data.all12,
          both12: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 13) {
        this.data.all13.x = temp[0]
        this.data.all13.y = temp[1]
        that.setData({
          all13 :this.data.all13,
          both13: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      } else if (_id == 14) {
        this.data.all14.x = temp[0]
        this.data.all14.y = temp[1]
        that.setData({
          all14: this.data.all14,
          both14: "left:" + temp[0] + "rpx;top:" + temp[1] + "rpx;"
        })
      }
       wx.stopBackgroundAudio()
       wx.playBackgroundAudio({ dataUrl: 'https://hrd.wyjzpw.com/playfive.mp3', title: 'weixin2' })
      tempPotins = this.data.points;
      let _isOk = true;
      for (let i = 0; i < tempPotins.length; i++) {
        for (let j = 0; j < tempComparePotins.length; j++) {
          if (tempPotins[i].num == tempComparePotins[j].num) {
            if (tempPotins[i].x != tempComparePotins[j].x) {
              _isOk = false;
              break;
            }
            if (tempPotins[i].y != tempComparePotins[j].y) {
              _isOk = false;
              break;
            }
          }
        }
      }
      if (_isOk) {
        wx.playBackgroundAudio({ dataUrl: 'https://hrd.wyjzpw.com/win.mp3', title: 'weixin2' })
        let newtime =  that.data.int.split(":");
        newtime = (parseInt(newtime[0]) * 60 + parseInt(newtime[1])) * 1000 + parseInt(newtime[2])
        let besttime =  that.data.besttime;
        if (newtime < besttime) {
          wx.request({
            url: app.globalData.allUrl + "/login/update_time",
            data: {
              openid: wx.getStorageSync("userid"),
              time: that.data.int,
              time_two: newtime
            },
            header: { 'content-type': "application/x-www-form-urlencoded" },
            method: 'POST',
            success: function (datas) {
              wx.setStorageSync("besttime", that.data.int)
              that.setData({
                besttime: that.data.int
              })
            }
          })  
        } 
        this.pauseGame();
        stop();
        let _ranks;
        let _jibai;
        if (newtime < 18000) {
          _ranks = "我是神！"
          _jibai = "99.99%"
        } else if (18000 <= newtime && newtime < 20000) {
          _ranks = "我是神！"
          _jibai = "99." + parseInt((Math.random() * 100)) + "%"
        } else if (20000 <= newtime && newtime < 22000) {
          _ranks = "王者五"
          _jibai = "98." + parseInt((Math.random() * 100)) + "%"
        } else if (22000 <= newtime && newtime < 24000) {
          _ranks = "王者四"
          _jibai = "98." + parseInt((Math.random() * 100)) + "%"
        } else if (24000 <= newtime && newtime < 26000) {
          _ranks = "王者三"
          _jibai = "97." + parseInt((Math.random() * 100)) + "%"
        } else if (26000 <= newtime && newtime < 28000) {
          _ranks = "王者二"
          _jibai = "97." + parseInt((Math.random() * 100)) + "%"
        } else if (28000 <= newtime && newtime < 30000) {
          _ranks = "王者一"
          _jibai = "96." + parseInt((Math.random() * 100)) + "%"
        } else if (30000 <= newtime && newtime < 35000) {
          _ranks = "大师"
          _jibai = "95." + parseInt((Math.random() * 100)) + "%"
        } else if (35000 <= newtime && newtime < 40000) {
          _ranks = "钻石"
          _jibai = "93." + parseInt((Math.random() * 100)) + "%"
        } else if (40000 <= newtime && newtime < 45000) {
          _ranks = "白金"
          _jibai = "92." + parseInt((Math.random() * 100)) + "%"
        } else if (45000 <= newtime && newtime < 50000) {
          _ranks = "黄金"
          _jibai = "91." + parseInt((Math.random() * 100)) + "%"
        } else if (50000 <= newtime && newtime < 60000) {
          _ranks = "白银"
          _jibai = "90." + parseInt((Math.random() * 100)) + "%"
        } else if (60000 <= newtime && newtime < 180000) {
          _ranks = "青铜"
          _jibai = "83." + parseInt((Math.random() * 100)) + "%"
        } else if (180000 <= newtime && newtime) {
          _ranks = "聚乙烯^-^"
          _jibai = "80." + parseInt((Math.random() * 100)) + "%"
        }
        that.setData({
          timeInt: that.data.int,
          duanwei: _ranks,
          jibai: _jibai,
          motaiHidden: false,
          light:""
        })    
      } else {
        this.data.steps++;
        this.setData({
          steps: this.data.steps
        })
      }
      //  console.log(this.data.points)
    }
  },
  startGame: function () {
    this.setData({
      canclick: true,
      currentState: "../../image/pause.png",
      currentTap: 'pauseGame',
      isReset: false
    })
    start(this);
  },
  pauseGame: function () {
    this.setData({
      canclick: false,
      currentState: "../../image/start.png",
      currentTap: 'startGame'
    })
    stop(this);
  },
  reset: function () {
    getNums(this);
    getAllPoints(this);
    this.setData({
      canclick: false,
      currentState: "../../image/start.png",
      currentTap: 'startGame',
      emptyPoint: [510, 510],
      steps: 0,
      isReset: true,
      light: ""
    })
    reset(this);
  },
  cancel:function(){
    this.setData({
      motaiHidden:true
    })
  },
  resetandcancel:function(){
this.reset();
this.cancel();
  }
})

function getNums(that) {
  /*var _arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
  var _arrary = [];
  while (_arr.length) {
    _arrary.push(_arr.splice(parseInt(Math.random() * _arr.length), 1)[0])
  }*/
  var _array = [];
  _array = puzzleList4[parseInt(Math.random() * puzzleList4.length)]
  that.setData({
    nums: _array,
  })
}

function getAllPoints(that) {
  var _x;
  var _y;
  that.data.points = [];
  for (var j = 0; j < that.data.nums.length; j++) {
    if (j % 4 == 0) {
      _x = 0;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    } else if (j % 4 == 1) {
      _x = 170;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    } else if (j % 4 == 2) {
      _x = 340;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    } else if (j % 4 == 3) {
      _x = 510;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    }

    that.data.points.push({
      num: that.data.nums[j],
      x: _x,
      y: _y,
    //  both: "left:" + _x +"rpx;top:"+_y+"rpx"
      all0: {num: that.data.nums[j],x: _x, y: _y,}
    })
    if(j==0){
      that.setData({
        both0: "left:" + _x + "rpx;top:" + _y + "rpx",
        all0: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 1) {
      that.setData({
        both1: "left:" + _x + "rpx;top:" + _y + "rpx",
          all1: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 2) {
      that.setData({
        both2: "left:" + _x + "rpx;top:" + _y + "rpx",
        all2: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 3) {
      that.setData({
        both3: "left:" + _x + "rpx;top:" + _y + "rpx",
        all3: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 4) {
      that.setData({
        both4: "left:" + _x + "rpx;top:" + _y + "rpx",
        all4: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 5) {
      that.setData({
        both5: "left:" + _x + "rpx;top:" + _y + "rpx",
        all5: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 6) {
      that.setData({
        both6: "left:" + _x + "rpx;top:" + _y + "rpx",
        all6: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 7) {
      that.setData({
        both7: "left:" + _x + "rpx;top:" + _y + "rpx",
        all7: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 8) {
      that.setData({
        both8: "left:" + _x + "rpx;top:" + _y + "rpx",
        all8: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 9) {
      that.setData({
        both9: "left:" + _x + "rpx;top:" + _y + "rpx",
        all9: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 10) {
      that.setData({
        both10: "left:" + _x + "rpx;top:" + _y + "rpx",
        all10: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 11) {
      that.setData({
        both11: "left:" + _x + "rpx;top:" + _y + "rpx",
        all11: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 12) {
      that.setData({
        both12: "left:" + _x + "rpx;top:" + _y + "rpx",
        all12: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 13) {
      that.setData({
        both13: "left:" + _x + "rpx;top:" + _y + "rpx",
        all13: { num: that.data.nums[j], x: _x, y: _y, }
      })
    } else if (j == 14) {
      that.setData({
        both14: "left:" + _x + "rpx;top:" + _y + "rpx",
        all14: { num: that.data.nums[j], x: _x, y: _y, }
      })
    }
  }
  that.setData({
    points: that.data.points
  })
}


function getCorrectPosition(that) {
  var _x;
  var _y;
  for (var j = 0; j < 15; j++) {
    if (j % 4 == 0) {
      _x = 0;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    } else if (j % 4 == 1) {
      _x = 170;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    } else if (j % 4 == 2) {
      _x = 340;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    } else if (j % 4 == 3) {
      _x = 510;
      if (parseInt(j / 4) == 0) {
        _y = 0;
      } else if (parseInt(j / 4) == 1) {
        _y = 170;
      } else if (parseInt(j / 4) == 2) {
        _y = 340;
      } else if (parseInt(j / 4) == 3) {
        _y = 510;
      }
    }
    that.data.correctPosition.push({
      num: j + 1,
      x: _x,
      y: _y
    })

  }
  that.setData({
    correctPosition: that.data.correctPosition
  })
}

function timer(that) {
  // console.log(that.data.millisecond)
  that.setData({
    millisecond: that.data.millisecond + 5
  })
  if (that.data.millisecond >= 100) {
    that.setData({
      millisecond: 0,
      second: that.data.second + 1
    })
  }
  if (that.data.second >= 60) {
    that.setData({
      second: 0,
      minute: that.data.minute + 1
    })
  }

  if (that.data.minute >= 60) {
    that.setData({
      minute: 0,
      hour: that.data.hour + 1
    })
  }
  that.setData({
    //int: that.data.hour + ":" + that.data.minute + ":" + that.data.second + ":" + that.data.millisecond
    int: that.data.minute + ":" + that.data.second + ":" + that.data.millisecond
  })
}

function start(that) {
  //  clearInterval(intt);
  //时间重置
  /*  that.setData({
      hour: 0,
      minute: 0,
      second: 0,
      millisecond: 0,
      int: '00:00:00',
    })*/
  intt = setInterval(function () { timer(that) }, 50);
}
function stop(that) {
  clearInterval(intt);
}
function reset(that) {
  clearInterval(intt);
  that.setData({
    hour: 0,
    minute: 0,
    second: 0,
    millisecond: 0,
    int: '00:00:00',
  })
}

function getBannder(that){
  wx.request({
    url: app.globalData.allUrl + "/login/image",
    data: {
    },
    header: { 'content-type': "application/x-www-form-urlencoded" },
    method: 'POST',
    success: function (res) {
     // console.log(res.data)
       that.setData({
         imageUrls:res.data
       })
    }
  })
}


function getCode(that) {
  wx.login({
    success: function (rese) {
      wx.request({
        url: app.globalData.allUrl + "/login/login",
        data: {
          code: rese.code,
        },
        header: { 'content-type': "application/x-www-form-urlencoded" },
        method: 'POST',
        success: function (datas) {
         // console.log(datas.data)
          if (!datas.data.time){
            datas.data.time="1439059"
          }
          wx.setStorageSync("userid", datas.data.openid)
          wx.setStorageSync("besttime", datas.data.time)
          that.setData({
            besttime: datas.data.time
          })
         // console.log(that.data.besttime)
        }
      })
    }
  })
}



const puzzleList4 = [
  [12, 3, 5, 11, 15, 4, 8, 6, 2, 13, 7, 10, 9, 14, 1],
  [1, 10, 3, 4, 13, 2, 12, 7, 6, 5, 8, 11, 15, 9, 14],
  [3, 11, 14, 2, 13, 8, 15, 10, 12, 6, 5, 1, 4, 7, 9],
  [8, 6, 10, 2, 12, 9, 11, 1, 14, 13, 3, 7, 5, 15, 4],
  [15, 10, 6, 2, 4, 5, 3, 9, 8, 12, 11, 13, 14, 1, 7],
  [14, 13, 1, 9, 12, 3, 8, 15, 11, 6, 4, 2, 10, 5, 7],
  [11, 3, 6, 7, 14, 4, 10, 8, 2, 1, 13, 15, 5, 9, 12],
  [3, 2, 11, 6, 5, 8, 7, 4, 1, 15, 9, 14, 13, 10, 12],
  [7, 13, 8, 5, 12, 3, 6, 4, 10, 9, 15, 11, 2, 1, 14],
  [1, 14, 5, 7, 15, 3, 11, 4, 12, 8, 10, 9, 13, 6, 2],
  [14, 4, 15, 8, 2, 10, 1, 9, 12, 11, 5, 6, 3, 7, 13],
  [2, 11, 1, 8, 5, 4, 12, 13, 14, 3, 10, 15, 9, 7, 6],
  [5, 10, 11, 2, 15, 9, 4, 8, 13, 14, 12, 1, 7, 6, 3],
  [4, 2, 15, 7, 9, 10, 14, 1, 6, 11, 5, 13, 8, 3, 12],
  [1, 5, 15, 8, 11, 6, 10, 13, 2, 3, 9, 7, 4, 12, 14],
  [3, 9, 13, 15, 8, 11, 10, 5, 7, 6, 4, 14, 12, 1, 2],
  [13, 4, 15, 10, 1, 9, 8, 11, 7, 12, 2, 6, 5, 3, 14],
  [4, 1, 12, 11, 7, 2, 9, 5, 8, 13, 15, 10, 14, 3, 6],
  [10, 8, 1, 13, 12, 2, 6, 9, 3, 7, 4, 11, 5, 15, 14],
  [6, 7, 13, 3, 9, 1, 2, 14, 12, 15, 11, 5, 8, 10, 4],
  [5, 13, 8, 4, 14, 6, 15, 10, 3, 12, 7, 9, 1, 2, 11],
  [3, 13, 15, 2, 9, 6, 8, 14, 4, 10, 12, 7, 11, 1, 5],
  [10, 5, 4, 11, 9, 2, 6, 15, 1, 7, 8, 13, 3, 14, 12],
  [6, 14, 3, 5, 13, 7, 11, 2, 4, 10, 1, 12, 8, 15, 9],
  [9, 2, 14, 6, 12, 15, 1, 5, 4, 11, 7, 3, 10, 8, 13],
  [5, 14, 9, 8, 15, 4, 3, 11, 13, 12, 6, 2, 1, 10, 7],
  [7, 10, 4, 11, 8, 14, 13, 2, 3, 12, 9, 6, 5, 1, 15],
  [14, 10, 6, 5, 11, 8, 1, 3, 4, 13, 7, 15, 2, 12, 9],
  [14, 13, 15, 8, 2, 12, 5, 4, 1, 3, 6, 10, 11, 9, 7],
  [11, 15, 6, 8, 14, 7, 9, 5, 2, 4, 13, 1, 10, 3, 12],
  [7, 15, 14, 9, 2, 1, 3, 11, 10, 12, 8, 5, 4, 6, 13],
  [5, 2, 15, 14, 7, 6, 4, 8, 1, 13, 9, 12, 10, 11, 3],
  [8, 10, 11, 1, 14, 13, 5, 3, 9, 12, 15, 4, 2, 7, 6],
  [8, 14, 7, 11, 6, 3, 12, 4, 10, 1, 15, 9, 2, 5, 13],
  [15, 8, 9, 6, 2, 14, 12, 3, 5, 10, 1, 13, 7, 4, 11],
  [6, 15, 7, 10, 1, 3, 12, 4, 8, 14, 5, 2, 9, 11, 13],
  [12, 9, 2, 4, 3, 14, 7, 5, 1, 6, 13, 11, 15, 8, 10],
  [13, 3, 15, 10, 2, 5, 9, 7, 6, 11, 1, 14, 8, 4, 12],
  [13, 11, 2, 8, 15, 1, 9, 5, 6, 12, 4, 3, 14, 10, 7],
  [7, 1, 5, 12, 15, 2, 8, 10, 3, 6, 9, 13, 11, 14, 4],
  [14, 13, 12, 1, 2, 8, 6, 11, 7, 10, 15, 3, 4, 9, 5],
  [3, 8, 13, 10, 12, 14, 5, 11, 1, 15, 9, 4, 7, 2, 6],
  [11, 6, 10, 14, 8, 2, 13, 4, 12, 9, 3, 5, 1, 7, 15],
  [7, 13, 3, 14, 9, 11, 12, 10, 2, 6, 1, 5, 4, 8, 15],
  [2, 3, 6, 4, 14, 12, 13, 1, 5, 10, 8, 11, 9, 7, 15],
  [11, 12, 9, 14, 8, 15, 10, 7, 1, 13, 5, 2, 3, 6, 4],
  [5, 11, 4, 15, 12, 10, 2, 1, 8, 14, 9, 13, 7, 6, 3],
  [14, 9, 13, 7, 1, 4, 2, 3, 8, 11, 15, 5, 10, 6, 12],
  [15, 5, 13, 2, 14, 4, 1, 6, 12, 3, 9, 10, 8, 7, 11],
  [10, 2, 15, 5, 12, 8, 7, 3, 6, 14, 11, 13, 4, 9, 1],
  [11, 5, 4, 2, 7, 13, 3, 1, 12, 9, 14, 6, 10, 15, 8],
  [13, 15, 4, 6, 1, 14, 11, 7, 10, 9, 8, 5, 3, 2, 12],
  [12, 13, 14, 11, 3, 8, 7, 10, 2, 1, 6, 9, 5, 4, 15],
  [12, 8, 15, 3, 9, 2, 5, 14, 4, 6, 11, 7, 1, 10, 13],
  [1, 13, 9, 2, 12, 6, 8, 7, 4, 11, 14, 5, 10, 15, 3],
  [9, 1, 15, 14, 5, 11, 2, 3, 12, 6, 10, 8, 7, 13, 4],
  [13, 2, 11, 14, 15, 4, 9, 6, 1, 3, 7, 10, 5, 8, 12],
  [12, 14, 6, 7, 4, 2, 3, 10, 15, 11, 1, 8, 9, 5, 13],
  [8, 14, 1, 4, 3, 6, 15, 12, 11, 7, 5, 10, 2, 9, 13],
  [8, 12, 9, 4, 3, 11, 15, 6, 5, 7, 2, 13, 14, 10, 1],
  [3, 10, 14, 9, 15, 8, 2, 6, 5, 13, 7, 12, 4, 11, 1],
  [7, 12, 5, 14, 2, 10, 11, 3, 13, 1, 4, 8, 15, 6, 9],
  [4, 15, 5, 11, 9, 12, 14, 13, 6, 7, 10, 2, 1, 3, 8],
  [10, 1, 3, 6, 11, 14, 5, 4, 15, 9, 13, 2, 12, 8, 7],
  [11, 2, 3, 4, 7, 6, 12, 15, 5, 13, 14, 10, 9, 1, 8],
  [11, 6, 5, 9, 15, 14, 4, 3, 1, 13, 12, 8, 10, 2, 7],
  [11, 1, 2, 6, 8, 4, 10, 7, 5, 13, 12, 3, 9, 14, 15],
  [4, 6, 2, 8, 12, 1, 5, 15, 9, 11, 7, 10, 13, 14, 3],
  [9, 7, 2, 8, 11, 5, 4, 15, 12, 1, 6, 13, 14, 10, 3],
  [12, 13, 15, 14, 6, 11, 7, 5, 1, 9, 4, 10, 3, 2, 8],
  [1, 13, 3, 9, 6, 14, 5, 2, 11, 15, 10, 7, 12, 4, 8],
  [13, 10, 11, 15, 2, 14, 7, 5, 6, 3, 9, 8, 4, 12, 1],
  [8, 13, 11, 3, 6, 15, 1, 14, 4, 10, 9, 5, 2, 7, 12],
  [11, 12, 4, 2, 9, 13, 10, 15, 3, 7, 8, 14, 6, 1, 5],
  [3, 15, 2, 12, 9, 10, 13, 6, 5, 8, 14, 7, 4, 11, 1],
  [8, 1, 6, 12, 14, 13, 11, 15, 10, 5, 2, 7, 3, 9, 4],
  [12, 10, 4, 9, 7, 3, 14, 11, 8, 1, 15, 2, 6, 5, 13],
  [3, 6, 15, 13, 2, 4, 9, 10, 7, 11, 8, 14, 1, 5, 12],
  [12, 8, 10, 13, 2, 5, 11, 4, 7, 14, 3, 15, 9, 1, 6],
  [13, 6, 7, 11, 12, 5, 4, 2, 1, 10, 9, 3, 8, 15, 14],
  [1, 10, 12, 6, 7, 13, 3, 9, 2, 15, 8, 14, 5, 4, 11],
  [11, 4, 13, 3, 1, 5, 6, 12, 2, 15, 14, 7, 9, 8, 10],
  [7, 12, 14, 11, 2, 4, 10, 13, 6, 1, 15, 8, 3, 5, 9],
  [15, 5, 9, 7, 4, 1, 6, 12, 14, 3, 2, 13, 11, 8, 10],
  [12, 6, 13, 7, 15, 14, 9, 3, 1, 5, 8, 11, 4, 2, 10],
  [6, 11, 15, 7, 12, 13, 8, 9, 14, 3, 1, 5, 2, 10, 4],
  [14, 15, 2, 12, 11, 10, 13, 9, 1, 5, 4, 3, 7, 8, 6],
  [2, 15, 6, 12, 11, 1, 10, 8, 3, 7, 9, 13, 4, 14, 5],
  [6, 3, 9, 12, 14, 2, 11, 5, 10, 8, 4, 13, 1, 15, 7],
  [4, 1, 7, 14, 9, 3, 6, 2, 12, 10, 15, 13, 11, 5, 8],
  [4, 3, 2, 15, 9, 11, 8, 10, 1, 7, 12, 14, 5, 13, 6],
  [1, 13, 11, 8, 10, 15, 3, 7, 14, 2, 6, 9, 5, 4, 12],
  [3, 14, 15, 12, 7, 9, 11, 5, 10, 2, 6, 4, 1, 8, 13],
  [14, 4, 7, 2, 11, 6, 3, 15, 5, 13, 8, 10, 12, 9, 1],
  [7, 12, 5, 3, 13, 1, 6, 4, 10, 2, 11, 15, 14, 9, 8],
  [3, 1, 7, 13, 6, 15, 12, 5, 11, 4, 9, 2, 14, 8, 10],
  [4, 8, 6, 2, 7, 5, 1, 13, 10, 9, 12, 11, 14, 15, 3],
  [13, 8, 9, 14, 2, 1, 7, 5, 10, 15, 12, 11, 3, 4, 6],
  [15, 2, 5, 3, 9, 7, 4, 12, 1, 6, 11, 13, 10, 8, 14]
] 